#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <SDL.h>
#include <SDL_image.h>

#include "../include/game.h"
#include "../include/misc.h"
#include "../include/list_bomb.h"

struct cell
{
	t_cell next;
	t_bomb bomb;
};

struct bomb_list
{
	t_cell first;
};

t_bomb_list bomb_list_init(t_bomb bomb) {
	assert(bomb);
	t_cell cell = malloc(sizeof(*cell));
	t_bomb_list bomb_list = malloc(sizeof(*bomb_list));
	if (!bomb_list || !cell)
		error("Memory error");
	cell->bomb = bomb;
	cell->next = NULL;
	bomb_list->first = cell;
	return bomb_list;
}

t_bomb_list list_add(t_bomb_list bomb_list, t_bomb bomb){
	assert(bomb_list);
	assert(bomb);

	t_cell cell=malloc(sizeof(*cell));
	if (!cell)
		error("Memory error");

	cell->bomb = bomb;
	cell->next = bomb_list->first;

	bomb_list->first=cell;

	return bomb_list;
}

t_cell get_first(t_bomb_list bomb_list) {
	assert(bomb_list);

	return bomb_list->first;
}

t_bomb get_bomb(t_cell cell) {
	assert(cell);

	return cell->bomb;
}

t_cell get_next_cell(t_cell cell) {
	assert(cell);

	return cell->next;
}

void bomb_list_display(t_bomb_list bomb_list, SDL_Surface *screen, t_map map){
	assert(bomb_list);
	assert(screen);
	t_cell key = get_first(bomb_list);
	while( get_next_cell(key) != NULL){
		bomb_display(get_bomb(key),screen, map);
		key=get_next_cell(key);
	}
}
